package dp;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * 264. 丑数 II
 */
public class P264 {
    public int nthUglyNumber(int n) {
        Set<Integer> numSet = new HashSet<>();
        numSet.add(1);
        int now = 0;
        do {
            Iterator<Integer> iterator = numSet.iterator();
            now = iterator.next();
            System.out.print(now + ",");
            iterator.remove();
            numSet.add(now * 2);
            numSet.add(now * 3);
            numSet.add(now * 5);
        } while (--n > 1);
        return now;
    }

    public static void main(String[] args) {
        int i = new P264().nthUglyNumber(10);
        System.out.println(i);
    }
}
